/**
 *  This library contains jQuery functions that help driver
 *  scripts complete tasks
 *
 * @author nicholas malacarne <nicholas.malacarne@gmail.com>
 */

// load a script by url (e.g. js/folder/script.js) -nm
// this function must be called BEFORE document ready -nm
$.loadScript = function( url ){
    
    // hold document ready -nm
    $.holdReady( true );
    
    // get requested script by url -nm
    $.getScript( url, function() {
        
      // unhold document ready -nm
      $.holdReady( false );
    });
    
}; // end function -nm

// used to help debug the page -nm
$.debugLog = function( data ){
    
    // comment this line for production (non chrome browser compatability) -nm
    console.log( data );
    
} // end function -nm

// checks the length of an input field -nm 
$.fn.checkLength = function(){

    // minimum length for input -nm
    var minLen = 5;
    
    // current length of input -nm
    var curLen = $( this ).val().length;
    
    // if user name length is less than min length -nm
    if ( curLen > 0 && curLen < minLen ){  

        // apply invalid style -nm
        $( this ).toggleClass( "inputstyleinvalid", true );
        
        // TODO: show user notification -nm
        
    }else{
        
        // remove invalid style -nm
        $( this ).toggleClass( "inputstyleinvalid", false );
        
        // TODO: hide user notification -nm
    }
    
    return this;
};

// checks input boxes to determine if input is valid -nm
$.inputOK = function(){
    
    // do we have any invalid input boxes -nm
   var inputOK = ( $( '.inputstyleinvalid' ).length > 0 ) ? false : true;
   
   // check each input field -nm
   $( ':input' ).each( function(){
       
       // if the field is empty -nm
       if ( $( this ).val() === "" ){
           
           // field is empty; input not ok -nm
           inputOK = false;
           
           // break each loop -nm
           return false;
       }
   } );
   
   return inputOK;
};
    
